#include<bits/stdc++.h>
using namespace std;
#define OK 1
#define ERROR 0
typedef int Status;
typedef char ElemType; 
typedef struct LNode{
	ElemType data;
	struct LNode *next;	
}LNode, *LinkList;

Status Init(LinkList &L)
{
	L = new LNode;
	if(!L) return ERROR;
	L->next = NULL;
	return OK;
}
Status Create(LinkList &L1, LinkList &L2)
{
	int i, j;
	string str1, str2;
	cin >> str1 >> str2;
	int n1 = str1.length();
	int n2 = str2.length();
	
	for(i = n1 - 1, j = n2 - 1; str1[i] == str2[j]; i --, j --);
	
	LNode *t1 = L1, *p;
	for(int k = 0; k <= i; k ++)
	{
		p = new LNode;
		if(!p) return ERROR;
		p->data = str1[k];
		t1->next = p;
		t1 = p;
	}
	LNode *t2 = L2;
	for(int k = 0; k <= j; k ++)
	{
		p = new LNode;
		if(!p) return ERROR;
		p->data = str2[k];
		t2->next = p;
		t2 = p;
	}
	if(n2 - j <= 1)
	{
		t1->next = NULL;
		t2->next = NULL;
	}
	else
	{
		p = new LNode;
		if(!p) return ERROR;
		p->data = str2[j + 1];
		t2->next = p;
		t1->next = p;
		t2 = p;
		for(int k = 2; k < n2 - j; k ++)
		{
			LNode *p = new LNode;
			if(!p) return ERROR;
			p->data = str2[j + k];
			t2->next = p;
			t2 = p;
		}
		t2->next = NULL;	
	}
	
	return OK;
}
void Show(LinkList L)
{
	LNode *p = L->next;
	while(p)
	{
		cout << p->data << ' ';
		p = p->next;
	}
	cout << endl;
}
/**************Begin*************/
LNode* find_addr(LinkList L1, LinkList L2) 
{
    LNode *p1 = L1->next, *p2 = L2->next;
    int len1 = 0, len2 = 0;
    // 求链表长度 
    while(p1)
    {
    	p1 = p1->next;
    	len1++;
	}
	while(p2)
	{
		p2 = p2->next;
		len2++;
	}
	// 重置指针到链表头
	p1 = L1->next;
	p2 = L2->next; 
	//先走完差值
	if(len1 < len2)
		for(int i = 0; i < len2 - len1; i++) p2 = p2->next;
	else
		for(int i = 0; i < len1 - len2; i++) p1 = p1->next;
	
	// 一起走直到第一个相同的字母或者走到末尾
	while(p1 && p2 && p1 != p2) // 不能写p1->data != p2->data 
	{
		p1 = p1->next;
		p2 = p2->next;
	}
	return p1;
}
/************End**************/
int main()
{
	LinkList L1;
	Init(L1);
	LinkList L2;
	Init(L2);
	
	Create(L1, L2);
	LNode *p = find_addr(L1, L2);
	if(p) cout << p->data << endl;
	else cout << "没有共同后缀";
	 
	return 0;
}